<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>排序算法可视化指南</title>
    <link rel="stylesheet" href="https://cdn.staticfile.org/font-awesome/6.4.0/css/all.min.css">
    <link rel="stylesheet" href="https://cdn.staticfile.org/tailwindcss/2.2.19/tailwind.min.css">
    <link href="https://fonts.googleapis.com/css2?family=Noto+Serif+SC:wght@400;500;600;700&family=Noto+Sans+SC:wght@300;400;500;700&display=swap" rel="stylesheet">
    <script src="https://cdn.jsdelivr.net/npm/mermaid@latest/dist/mermaid.min.js"></script>
    <style>
        body {
            font-family: 'Noto Sans SC', Tahoma, Arial, Roboto, "Droid Sans", "Helvetica Neue", "Droid Sans Fallback", "Heiti SC", "Hiragino Sans GB", Simsun, sans-serif;
            background-color: #f9f9f9;
            color: #333;
        }
        h1, h2, h3, h4 {
            font-family: 'Noto Serif SC', serif;
        }
        .hero-gradient {
            background: linear-gradient(135deg, #6B73FF 0%, #000DFF 50%, #0052D9 100%);
        }
        .card-hover {
            transition: all 0.3s ease;
        }
        .card-hover:hover {
            transform: translateY(-5px);
            box-shadow: 0 20px 25px -5px rgba(0, 0, 0, 0.1), 0 10px 10px -5px rgba(0, 0, 0, 0.04);
        }
        .algorithm-icon {
            font-size: 2rem;
            margin-bottom: 1rem;
            color: #3B82F6;
        }
        .complexity-badge {
            display: inline-block;
            padding: 0.25rem 0.5rem;
            border-radius: 9999px;
            font-weight: 500;
        }
        .time-complexity {
            background-color: #DBEAFE;
            color: #1E40AF;
        }
        .space-complexity {
            background-color: #D1FAE5;
            color: #065F46;
        }
        .chart-container {
            background-color: white;
            border-radius: 0.5rem;
            padding: 1.5rem;
            box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
        }
        .footer-link {
            transition: all 0.3s ease;
        }
        .footer-link:hover {
            color: #93C5FD;
        }
    </style>
</head>
<body class="antialiased">
    <!-- Hero Section -->
    <section class="hero-gradient text-white py-20 px-4 sm:px-6 lg:px-8">
        <div class="max-w-4xl mx-auto text-center">
            <h1 class="text-4xl md:text-5xl font-bold mb-6">排序算法精要指南</h1>
            <p class="text-xl md:text-2xl mb-8 opacity-90">探索计算机科学中最基础而强大的排序技术</p>
            <div class="flex justify-center">
                <div class="inline-flex items-center bg-white bg-opacity-20 rounded-full px-6 py-3">
                    <i class="fas fa-sort-amount-down-alt mr-2"></i>
                    <span>10种经典排序算法解析</span>
                </div>
            </div>
        </div>
    </section>

    <!-- Introduction Section -->
    <section class="py-16 px-4 sm:px-6 lg:px-8">
        <div class="max-w-4xl mx-auto">
            <div class="bg-white rounded-xl shadow-md p-8">
                <h2 class="text-3xl font-bold mb-6 text-gray-800">排序的艺术与科学</h2>
                <p class="text-lg text-gray-700 mb-6 leading-relaxed">
                    排序是计算机科学中一个基本而重要的操作。高效的排序算法是现代计算的基础，从数据库查询到用户界面渲染，无处不在。不同的排序算法各有所长，理解它们的特性和适用场景是每位开发者的基本功。
                </p>
                <div class="flex flex-wrap gap-4 mt-6">
                    <div class="flex items-center">
                        <div class="w-3 h-3 rounded-full bg-blue-500 mr-2"></div>
                        <span class="text-gray-700">时间复杂度</span>
                    </div>
                    <div class="flex items-center">
                        <div class="w-3 h-3 rounded-full bg-green-500 mr-2"></div>
                        <span class="text-gray-700">空间复杂度</span>
                    </div>
                    <div class="flex items-center">
                        <div class="w-3 h-3 rounded-full bg-purple-500 mr-2"></div>
                        <span class="text-gray-700">稳定性</span>
                    </div>
                    <div class="flex items-center">
                        <div class="w-3 h-3 rounded-full bg-yellow-500 mr-2"></div>
                        <span class="text-gray-700">适用场景</span>
                    </div>
                </div>
            </div>
        </div>
    </section>

    <!-- Algorithm Comparison Chart -->
    <section class="py-12 px-4 sm:px-6 lg:px-8 bg-gray-50">
        <div class="max-w-6xl mx-auto">
            <h2 class="text-3xl font-bold text-center mb-12 text-gray-800">排序算法性能对比</h2>
            <div class="chart-container">
                <div class="mermaid">
                    %%{init: {'theme': 'base', 'themeVariables': { 'primaryColor': '#EFF6FF'}}}%%
                    xychart-beta
                        title "排序算法时间复杂度对比"
                        x-axis ["冒泡", "选择", "插入", "希尔", "归并", "快速", "堆", "计数", "桶", "基数"]
                        y-axis "时间复杂度" 0 --> 100
                        bar [50, 50, 50, 30, 20, 20, 20, 10, 15, 15]
                        line [50, 50, 20, 30, 20, 40, 20, 10, 15, 25]
                </div>
            </div>
        </div>
    </section>

    <!-- Algorithms Grid -->
    <section class="py-16 px-4 sm:px-6 lg:px-8">
        <div class="max-w-6xl mx-auto">
            <h2 class="text-3xl font-bold text-center mb-12 text-gray-800">十大排序算法详解</h2>
            <div class="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-8">
                <!-- Bubble Sort -->
                <div class="bg-white rounded-xl shadow-md overflow-hidden card-hover">
                    <div class="p-6">
                        <div class="algorithm-icon">
                            <i class="fas fa-bubbles"></i>
                        </div>
                        <h3 class="text-xl font-bold mb-2 text-gray-800">冒泡排序</h3>
                        <p class="text-gray-600 mb-4">通过重复比较相邻元素并交换它们，将最大元素"冒泡"到数组末尾。</p>
                        <div class="flex flex-wrap gap-2 mb-4">
                            <span class="complexity-badge time-complexity">O(n²)</span>
                            <span class="complexity-badge space-complexity">O(1)</span>
                        </div>
                        <div class="text-gray-700">
                            <p class="font-medium text-green-600 mb-1">优点：</p>
                            <p class="mb-3">简单易懂，适用于少量数据</p>
                            <p class="font-medium text-red-600 mb-1">缺点：</p>
                            <p>效率低，不适合大型数据集</p>
                        </div>
                    </div>
                </div>

                <!-- Selection Sort -->
                <div class="bg-white rounded-xl shadow-md overflow-hidden card-hover">
                    <div class="p-6">
                        <div class="algorithm-icon">
                            <i class="fas fa-mouse-pointer"></i>
                        </div>
                        <h3 class="text-xl font-bold mb-2 text-gray-800">选择排序</h3>
                        <p class="text-gray-600 mb-4">每次从未排序部分选择最小元素，放到已排序部分的末尾。</p>
                        <div class="flex flex-wrap gap-2 mb-4">
                            <span class="complexity-badge time-complexity">O(n²)</span>
                            <span class="complexity-badge space-complexity">O(1)</span>
                        </div>
                        <div class="text-gray-700">
                            <p class="font-medium text-green-600 mb-1">优点：</p>
                            <p class="mb-3">简单，内存使用少</p>
                            <p class="font-medium text-red-600 mb-1">缺点：</p>
                            <p>性能差，不适合大型数据集</p>
                        </div>
                    </div>
                </div>

                <!-- Insertion Sort -->
                <div class="bg-white rounded-xl shadow-md overflow-hidden card-hover">
                    <div class="p-6">
                        <div class="algorithm-icon">
                            <i class="fas fa-sort-numeric-up"></i>
                        </div>
                        <h3 class="text-xl font-bold mb-2 text-gray-800">插入排序</h3>
                        <p class="text-gray-600 mb-4">将未排序元素逐个插入到已排序部分的合适位置。</p>
                        <div class="flex flex-wrap gap-2 mb-4">
                            <span class="complexity-badge time-complexity">O(n²)</span>
                            <span class="complexity-badge space-complexity">O(1)</span>
                        </div>
                        <div class="text-gray-700">
                            <p class="font-medium text-green-600 mb-1">优点：</p>
                            <p class="mb-3">简单，适用于小规模或几乎已排序的数据</p>
                            <p class="font-medium text-red-600 mb-1">缺点：</p>
                            <p>在大数据集上效率低</p>
                        </div>
                    </div>
                </div>

                <!-- Merge Sort -->
                <div class="bg-white rounded-xl shadow-md overflow-hidden card-hover">
                    <div class="p-6">
                        <div class="algorithm-icon">
                            <i class="fas fa-code-branch"></i>
                        </div>
                        <h3 class="text-xl font-bold mb-2 text-gray-800">归并排序</h3>
                        <p class="text-gray-600 mb-4">将数组分割成两个子数组，分别排序后合并。</p>
                        <div class="flex flex-wrap gap-2 mb-4">
                            <span class="complexity-badge time-complexity">O(n log n)</span>
                            <span class="complexity-badge space-complexity">O(n)</span>
                        </div>
                        <div class="text-gray-700">
                            <p class="font-medium text-green-600 mb-1">优点：</p>
                            <p class="mb-3">稳定排序，时间复杂度优秀</p>
                            <p class="font-medium text-red-600 mb-1">缺点：</p>
                            <p>需要额外的内存空间</p>
                        </div>
                    </div>
                </div>

                <!-- Quick Sort -->
                <div class="bg-white rounded-xl shadow-md overflow-hidden card-hover">
                    <div class="p-6">
                        <div class="algorithm-icon">
                            <i class="fas fa-bolt"></i>
                        </div>
                        <h3 class="text-xl font-bold mb-2 text-gray-800">快速排序</h3>
                        <p class="text-gray-600 mb-4">选择基准元素分割数组，递归排序子数组。</p>
                        <div class="flex flex-wrap gap-2 mb-4">
                            <span class="complexity-badge time-complexity">O(n log n)</span>
                            <span class="complexity-badge space-complexity">O(log n)</span>
                        </div>
                        <div class="text-gray-700">
                            <p class="font-medium text-green-600 mb-1">优点：</p>
                            <p class="mb-3">排序速度快，适用于大数据集</p>
                            <p class="font-medium text-red-600 mb-1">缺点：</p>
                            <p>最坏情况下性能差，不稳定</p>
                        </div>
                    </div>
                </div>

                <!-- Heap Sort -->
                <div class="bg-white rounded-xl shadow-md overflow-hidden card-hover">
                    <div class="p-6">
                        <div class="algorithm-icon">
                            <i class="fas fa-project-diagram"></i>
                        </div>
                        <h3 class="text-xl font-bold mb-2 text-gray-800">堆排序</h3>
                        <p class="text-gray-600 mb-4">构建最大堆，取出堆顶元素并调整堆结构。</p>
                        <div class="flex flex-wrap gap-2 mb-4">
                            <span class="complexity-badge time-complexity">O(n log n)</span>
                            <span class="complexity-badge space-complexity">O(1)</span>
                        </div>
                        <div class="text-gray-700">
                            <p class="font-medium text-green-600 mb-1">优点：</p>
                            <p class="mb-3">不需要额外空间，性能稳定</p>
                            <p class="font-medium text-red-600 mb-1">缺点：</p>
                            <p>不稳定排序，堆调整复杂</p>
                        </div>
                    </div>
                </div>

                <!-- Counting Sort -->
                <div class="bg-white rounded-xl shadow-md overflow-hidden card-hover">
                    <div class="p-6">
                        <div class="algorithm-icon">
                            <i class="fas fa-list-ol"></i>
                        </div>
                        <h3 class="text-xl font-bold mb-2 text-gray-800">计数排序</h3>
                        <p class="text-gray-600 mb-4">计算每个元素的出现次数来排序，适用于范围小的整数。</p>
                        <div class="flex flex-wrap gap-2 mb-4">
                            <span class="complexity-badge time-complexity">O(n + k)</span>
                            <span class="complexity-badge space-complexity">O(k)</span>
                        </div>
                        <div class="text-gray-700">
                            <p class="font-medium text-green-600 mb-1">优点：</p>
                            <p class="mb-3">时间复杂度低，适合整数排序</p>
                            <p class="font-medium text-red-600 mb-1">缺点：</p>
                            <p>不适合数据范围大的情况</p>
                        </div>
                    </div>
                </div>

                <!-- Bucket Sort -->
                <div class="bg-white rounded-xl shadow-md overflow-hidden card-hover">
                    <div class="p-6">
                        <div class="algorithm-icon">
                            <i class="fas fa-boxes"></i>
                        </div>
                        <h3 class="text-xl font-bold mb-2 text-gray-800">桶排序</h3>
                        <p class="text-gray-600 mb-4">将元素分配到桶中，对每个桶排序后合并。</p>
                        <div class="flex flex-wrap gap-2 mb-4">
                            <span class="complexity-badge time-complexity">O(n + k)</span>
                            <span class="complexity-badge space-complexity">O(n)</span>
                        </div>
                        <div class="text-gray-700">
                            <p class="font-medium text-green-600 mb-1">优点：</p>
                            <p class="mb-3">适合数据分布均匀的情况</p>
                            <p class="font-medium text-red-600 mb-1">缺点：</p>
                            <p>需要额外空间，分布不均时性能差</p>
                        </div>
                    </div>
                </div>

                <!-- Radix Sort -->
                <div class="bg-white rounded-xl shadow-md overflow-hidden card-hover">
                    <div class="p-6">
                        <div class="algorithm-icon">
                            <i class="fas fa-sort-amount-down"></i>
                        </div>
                        <h3 class="text-xl font-bold mb-2 text-gray-800">基数排序</h3>
                        <p class="text-gray-600 mb-4">按数字的每位从低到高或反向进行排序。</p>
                        <div class="flex flex-wrap gap-2 mb-4">
                            <span class="complexity-badge time-complexity">O(n * k)</span>
                            <span class="complexity-badge space-complexity">O(n + k)</span>
                        </div>
                        <div class="text-gray-700">
                            <p class="font-medium text-green-600 mb-1">优点：</p>
                            <p class="mb-3">对整数非常高效</p>
                            <p class="font-medium text-red-600 mb-1">缺点：</p>
                            <p>不适用所有数据类型，空间要求高</p>
                        </div>
                    </div>
                </div>

                <!-- Shell Sort -->
                <div class="bg-white rounded-xl shadow-md overflow-hidden card-hover">
                    <div class="p-6">
                        <div class="algorithm-icon">
                            <i class="fas fa-layer-group"></i>
                        </div>
                        <h3 class="text-xl font-bold mb-2 text-gray-800">希尔排序</h3>
                        <p class="text-gray-600 mb-4">基于插入排序，比较相距一定间隔的元素。</p>
                        <div class="flex flex-wrap gap-2 mb-4">
                            <span class="complexity-badge time-complexity">O(n²)</span>
                            <span class="complexity-badge space-complexity">O(1)</span>
                        </div>
                        <div class="text-gray-700">
                            <p class="font-medium text-green-600 mb-1">优点：</p>
                            <p class="mb-3">比简单插入排序更高效</p>
                            <p class="font-medium text-red-600 mb-1">缺点：</p>
                            <p>性能依赖间隔序列选择</p>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </section>

    <!-- Algorithm Selection Guide -->
    <section class="py-16 px-4 sm:px-6 lg:px-8 bg-gray-50">
        <div class="max-w-4xl mx-auto">
            <h2 class="text-3xl font-bold text-center mb-12 text-gray-800">如何选择合适的排序算法？</h2>
            <div class="bg-white rounded-xl shadow-md p-8">
                <div class="mermaid">
                    flowchart TD
                        A[需要排序的数据] --> B{数据规模}
                        B -->|小规模(n<100)| C[插入排序/冒泡排序]
                        B -->|中等规模| D{是否需要稳定排序?}
                        B -->|大规模| E{数据是否基本有序?}
                        D -->|是| F[归并排序]
                        D -->|否| G[快速排序/堆排序]
                        E -->|是| H[插入排序]
                        E -->|否| I{数据范围是否小?}
                        I -->|是| J[计数排序/桶排序/基数排序]
                        I -->|否| K[快速排序/堆排序]
                        C --> L[完成]
                        F --> L
                        G --> L
                        H --> L
                        J --> L
                        K --> L
                </div>
                <div class="mt-8">
                    <h3 class="text-xl font-bold mb-4 text-gray-800">选择排序算法的考量因素：</h3>
                    <ul class="list-disc pl-6 space-y-2 text-gray-700">
                        <li><strong>数据规模：</strong>小规模数据适合简单排序(O(n²))，大规模需要O(n log n)算法</li>
                        <li><strong>数据分布：</strong>是否基本有序？是否包含大量重复元素？</li>
                        <li><strong>稳定性：</strong>是否需要保持相等元素的原始顺序？</li>
                        <li><strong>内存限制：</strong>是否有严格的内存使用限制？</li>
                        <li><strong>数据类型：</strong>排序的是整数、字符串还是复杂对象？</li>
                    </ul>
                </div>
            </div>
        </div>
    </section>

    <!-- Footer -->
    <footer class="bg-gray-900 text-gray-300 py-12 px-4 sm:px-6 lg:px-8">
        <div class="max-w-6xl mx-auto">
            <div class="flex flex-col items-center text-center">
                <h3 class="text-xl font-bold mb-4">技术小馆</h3>
                <a href="http://www.yuque.com/jtostring" class="footer-link text-gray-400 hover:text-white mb-6">http://www.yuque.com/jtostring</a>
                <p class="text-sm text-gray-500">© 2023 排序算法可视化指南. 保留所有权利.</p>
            </div>
        </div>
    </footer>

    <script>
        mermaid.initialize({
            startOnLoad: true,
            theme: 'default',
            flowchart: {
                useMaxWidth: false,
                htmlLabels: true,
                curve: 'basis'
            }
        });
    </script>
</body>
</html>